I have added an admin grid using UI component in my custom module. Now I want to change the column width of admin grid.
This is the code that I am using for adding column in admin grid :
 <column name="product_title">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="editor" xsi:type="array">
 <item name="editorType" xsi:type="string">text</item>
 <item name="validation" xsi:type="array">
 <item name="required-entry" xsi:type="boolean">true</item>
 </item>
 </item>
 <item name="filter" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true">Title</item>
 <item name="sortOrder" xsi:type="number">20</item>
 </item>
 </argument>
</column>
Please Help me
- 
 Did you check here magento.stackexchange.com/questions/76426/…Sukeshini– Sukeshini2016年12月29日 05:51:34 +00:00Commented Dec 29, 2016 at 5:51
4 Answers 4
At the moment on Magento 2.3.2 the only working solution requires adding configuration in 2 peaces in List (Grid) UI component:
- Setup resizeConfigfor columns config.
- Setup resizeDefaultWidthfor specific column.
- Setup resizeEnabledfor specific column (optional).
Here is an example:
<?xml version="1.0" encoding="UTF-8"?> 
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Ui/etc/ui_configuration.xsd">
 <columns name="columns">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="resizeConfig" xsi:type="array">
 <item name="enabled" xsi:type="boolean">true</item><!-- This is required configuration -->
 </item>
 </item>
 </argument>
 <column name="column_name">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="resizeEnabled" xsi:type="boolean">false</item><!-- "true" allows admin user to change column width (default value); "false" - disallows admin user to change column width -->
 <item name="resizeDefaultWidth" xsi:type="number">100</item><!-- needed column width in pixels -->
 </item>
 </argument>
 </column>
 </columns>
</listing>
The answer why this works only in the way I've described is in JS function initResize.
- 
 Thank you so fucking much!Tailtiu– Tailtiu2024年09月19日 07:37:51 +00:00Commented Sep 19, 2024 at 7:37
it may help just giving you example to use just like in new version of magento used.
<block class="Magento\Backend\Block\Widget\Grid\Column" as="package">
 <arguments>
 <argument name="header" xsi:type="string" translate="true">Design</argument>
 <argument name="type" xsi:type="string">options</argument>
 <argument name="options" xsi:type="options" model="Magento\Framework\View\Design\Theme\Label\Options"/>
 <argument name="width" xsi:type="string">150px</argument>
 <argument name="index" xsi:type="string">design</argument>
 </arguments>
 </block>
you can look width as argument in xml
<argument name="width" xsi:type="string">150px</argument>
Also if you have to follow strict ui components you can use Resize component.
example from source link
<column name="creation_time">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="resizeEnabled" xsi:type="boolean">true</item>
 <item name="resizeDefaultWidth" xsi:type="string">60</item>
 </item>
 </argument>
</column>
hope it will work for you
- 
 This is used for Grid UI component?Khoa Truong– Khoa Truong2016年12月29日 05:55:01 +00:00Commented Dec 29, 2016 at 5:55
- 
 1ah, can also used devdocs.magento.com/guides/v2.0/ui-components/… resize componentsliyakat– liyakat2016年12月29日 06:00:05 +00:00Commented Dec 29, 2016 at 6:00
- 
 1Still no change in my column width. :-(E.B– E.B2016年12月29日 06:22:05 +00:00Commented Dec 29, 2016 at 6:22
- 
 1I m also facing same issue.Please help.Vindhuja– Vindhuja2016年12月29日 12:38:55 +00:00Commented Dec 29, 2016 at 12:38
- 
 devdocs.magento.com/guides/v2.0/ui-components/… follow this step by step i am sure you will get it doneliyakat– liyakat2016年12月29日 12:51:18 +00:00Commented Dec 29, 2016 at 12:51
You can use resizeDefaultWidth to change column with, required resizeEnabled = false,
Example code here.
<actionsColumn name="actions" class="Magento\Search\Ui\Component\Listing\Column\SynonymActions">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="resizeEnabled" xsi:type="boolean">false</item>
 <item name="resizeDefaultWidth" xsi:type="string">107</item>
 </item>
 </argument>
 </actionsColumn>
I tried all the given answers and no luck.
Then I resolved by adding some css to my output of column data.
<column name="detail_info" class="Vendor\Module\Ui\Component\Listing\Column\DetailInfo">
 <argument name="data" xsi:type="array">
 <item name="config" xsi:type="array">
 <item name="filter" xsi:type="string">text</item>
 <item name="label" xsi:type="string" translate="true">Detail Information</item>
 <item name="sortOrder" xsi:type="number">10</item>
 <item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
 </item>
 </argument>
 </column>
DetailInfo.php file I wrapped my output to div with some width.
$items['detail_info'] = '<div style="300px">'.$items['detail_info'].'</div>';